package com.ts.api.module.distribute.service.impl;


import com.gitee.apanlh.util.date.DateUtils;
import com.ts.api.module.distribute.dao.DistributePvDao;
import com.ts.api.module.distribute.entity.DistributeGroupPv;
import com.ts.api.module.distribute.entity.DistributePv;
import com.ts.api.module.distribute.entity.bo.DistributeLinkBO;
import com.ts.api.module.distribute.service.DistributePvService;
import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 智能分配，子链接PVService业务层处理
 *
 * @author ts
 * @date 2023-09-13
 */
@Service
public class DistributePvServiceImpl implements DistributePvService {
    @Autowired
    private DistributePvDao distributePvDao;

    @Override
    public int insertGroupPv(String ip, UserAgent userAgent, Long groupId) {
        DistributeGroupPv distributePv = new DistributeGroupPv();
        distributePv.setCreateTime(DateUtils.currentTime());
        distributePv.setLoanDistributeGroupId(groupId);
        distributePv.setIp(ip);
        distributePv.setBrowserName(userAgent.getBrowser().getName());
        distributePv.setOsName(userAgent.getOperatingSystem().getName());
        distributePv.setDeviceType(userAgent.getOperatingSystem().getDeviceType().getName());
        return distributePvDao.insertGroupPv(distributePv);
    }

    @Override
    public int insertLinkPv(String ip, UserAgent userAgent, DistributeLinkBO distributeLinkBO) {
        DistributePv distributePv = new DistributePv();
        distributePv.setCreateTime(DateUtils.currentTime());
        distributePv.setLoanDistributeGroupId(distributeLinkBO.getGroupId());
        distributePv.setLoanDistributeId(distributeLinkBO.getId());
        distributePv.setIp(ip);
        distributePv.setBrowserName(userAgent.getBrowser().getName());
        distributePv.setOsName(userAgent.getOperatingSystem().getName());
        distributePv.setDeviceType(userAgent.getOperatingSystem().getDeviceType().getName());
        return distributePvDao.insertLinkPv(distributePv);
    }
}
